/*
 * Copyright (c) 2020-2021, Bluetrum Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020/12/10     greedyhao    The first version
 */

/**
 * Notice!
 * All functions or data that are called during an interrupt need to be in RAM.
 * You can do it the way exception_isr() does.
 */

#include <rtthread.h>
#include "board.h"
//#include "oled_ssd1306.h"

void ssd1306_TestAll(void);
void ssd1306_refresh(void);


void board_scanio_init(void);

int test_modbus_rtu_slave(void);



struct rt_semaphore sem_oled_update;

void oled_update(void)
{
    rt_sem_release(&(sem_oled_update));
}


int main(void)
{

//    uint8_t pin_res = rt_pin_get("PA.0");
//    uint8_t pin_dc = rt_pin_get("PA.1");
//    uint8_t pin_cs = rt_pin_get("PA.5");
//
//    rt_pin_mode(pin_res, PIN_MODE_OUTPUT);
//    rt_pin_mode(pin_dc, PIN_MODE_OUTPUT);
//    rt_pin_mode(pin_cs, PIN_MODE_OUTPUT);
//
//    rt_pin_write(pin_res,PIN_HIGH);
//    rt_pin_write(pin_dc,PIN_HIGH);
//    rt_pin_write(pin_cs,PIN_LOW);

    rt_sem_init(&(sem_oled_update), "oledupdate", 0, RT_IPC_FLAG_FIFO);

    rt_kprintf("Hello, world\n");

    board_scanio_init();

    //oled_ssd1306_init();

    test_modbus_rtu_slave();
    ssd1306_TestAll();

    rt_thread_mdelay(1000);

    int rc = 0;
    while (1)
    {
        rc = rt_sem_take(&(sem_oled_update),500);
        if(rc == RT_EOK)
        {

        }

        ssd1306_refresh();

        rt_thread_mdelay(10);
    }
}
